home *** CD-ROM | disk | FTP | other *** search
/ Amiga Developer CD 2.1 / Amiga Developer CD v2.1.iso / Reference / DevCon / Washington_1988 / DevCon88.1 / Assembler / subroutines / trig.asm < prev   
Encoding:
Assembly Source File  |  1992-08-27  |  3.3 KB  |  106 lines

  1. ;
  2. ; Copyright (c) 1988 Commodore-Amiga, Inc.
  3. ;
  4. ; Executables based on this information may be used in software
  5. ; for Commodore Amiga computers.  All other rights reserved.
  6. ;
  7. ; This information is provided "as is"; no warranties are made.
  8. ; All use is at your own risk, and no liability or responsibility is assumed.
  9. ;
  10.  
  11.         CODE
  12.  
  13.         XDEF    Sine,Cosine
  14.  
  15. ;=============================================================================
  16. ;   res = Sine( multiplier, theta )
  17. ;    D0            D0          D1
  18. ;
  19. ; A fast fixed point routine to return a value multiplied by sin( theta )
  20. ;============================================================================
  21. Sine        move.w    d2,-(sp)
  22.         move.w    d0,-(sp)
  23.         bpl.s    5$
  24.         neg.w    d0
  25. 5$        ext.l    d1
  26.         divu.w    #90,d1            ; get angle in range 0-89
  27.         move.w    d1,d2            ; lower word = quadrant 0-3
  28.         swap    d1            ; get actual angle
  29.         btst.b    #0,d2            ; if quadrant 1 or 3...
  30.         beq.s    10$            ; ...reverse index value
  31.         neg.w    d1
  32.         addi.w    #90,d1
  33. 10$        asl.w    #1,d1            ; compute index into table
  34.         mulu.w    SinCosTable(pc,d1.w),d0    ; multiply by (sine*65536)
  35.         swap    d0            ; divide by 65536
  36.         bpl.s    15$            ; if msw >= $8000 round up
  37.         addq.w    #1,d0
  38. 15$        btst.b    #1,d2            ; if quadrant > 1 ...
  39.         beq.s    20$            ; ...negate the result
  40.         neg.w    d0
  41. 20$        ext.l    d0            ; make result a longword
  42.         move.w    (sp)+,d1        was original negative
  43.         bpl.s    30$            no
  44.         neg.l    d0            yes so negate result
  45. 30$        move.w    (sp)+,d2
  46.         rts
  47.  
  48.  
  49. ;=============================================================================
  50. ;   res = Cosine( multiplier, theta )
  51. ;    D0            D0          D1
  52. ;
  53. ; Fast fixed point routine to return a value multiplied by cos( theta )
  54. ;============================================================================
  55. Cosine        move.w    d2,-(sp)
  56.         move.w    d0,-(sp)        save multiplier
  57.         bpl.s    5$            make it positive
  58.         neg.w    d0
  59. 5$        ext.l    d1
  60.         divu.w    #90,d1            ; get angle in range 0-89
  61.         moveq.l    #3,d2            ; D2 = quadrant 0-3
  62.         and.w    d1,d2
  63.         swap    d1            ; get actual angle
  64.         btst.b    #0,d2            ; if quadrant 0 or 2...
  65.         bne.s    10$            ; ...reverse the index
  66.         neg.w    d1
  67.         addi.w    #90,d1
  68. 10$        asl.w    #1,d1            ; compute index into table
  69.         mulu.w    SinCosTable(pc,d1.w),d0    ; multiply by (cosine*65536)
  70.         swap    d0            ; divide by 65536
  71.         bpl.s    15$            ; if msw >= $8000 round up
  72.         addq.w    #1,d0
  73. 15$        cmpi.w    #1,d2            ; if quadrant=1 or ...
  74.         beq.s    20$            ; ...quadrant=2 ...
  75.         cmpi.w    #2,d2            ; ...negate result
  76.         bne.s    30$
  77. 20$        neg.w    d0
  78. 30$        ext.l    d0            ; make result a longword
  79.         move.w    (sp)+,d1        was original negative ?
  80.         bpl.s    40$            no
  81.         neg.l    d0            yes, negate result
  82. 40$        move.w    (sp)+,d2
  83.         rts
  84.  
  85. ;============================================================================
  86. ; table of sines or cosines for 0-89 degrees expressed as fractions of 65536
  87. ;============================================================================
  88. SinCosTable    DC.W    00000,01144,02287,03430,04571,05712
  89.         DC.W    06850,07987,09121,10252,11380,12505
  90.         DC.W    13625,14742,15854,16962,18064,19161
  91.         DC.W    20251,21336,22414,23486,24550,25607
  92.         DC.W    26655,27696,28729,29752,30767,31772
  93.         DC.W    32768,33753,34728,35693,36647,37589
  94.         DC.W    38521,39440,40347,41243,42125,42995
  95.         DC.W    43851,44695,45524,46340,47142,47929
  96.         DC.W    48702,49460,50203,50930,51642,52339
  97.         DC.W    53019,53683,54331,54962,55577,56174
  98.         DC.W    56755,57318,57864,58392,58902,59395
  99.         DC.W    59869,60325,60763,61182,61583,61965
  100.         DC.W    62327,62671,62996,63302,63588,63855
  101.         DC.W    64103,64331,64539,64728,64897,65047
  102.         DC.W    65176,65286,65375,65445,65495,65525
  103.         DC.W    65535
  104.  
  105.         END
  106.